<?php
class CrmHelperController  extends Zone_Action{
	public function autolocalAction(){
		$id = getInt('parent_id');
		$locals = $this->Model->fetchAll("SELECT * 
			FROM `locations` WHERE `parent_id`='$id'");
		die(json_encode($locals));	
	}

	public function customerAction(){
		$name = get('s','');
		if( $name === '' ){
			die('[]');
		}	
		
		$cus = $this->Model->fetchAll("SELECT 
			`a`.`ID`,`a`.`name`
			FROM `crm_customers` as `a`			
			WHERE `a`.`is_draft`='no' 
				AND `a`.`name` LIKE '%$name%' LIMIT 10");
		die(json_encode($cus));		
	}

	public function contactAction(){
		$name = get('s','');
		if( $name === '' ){
			die('[]');
		}		
		$cus = $this->Model->fetchAll("SELECT 
			`a`.`ID`,`a`.`title`
			FROM `crm_contacts` as `a`			
			WHERE `a`.`is_draft`='no' 
				AND `a`.`title` LIKE '%$name%' LIMIT 10");
		die(json_encode($cus));		
	}	
}	